﻿Imports Crystal.CLL
Imports Infragistics.Win.UltraWinGrid

Public Class ExistingInvestorFund
    Inherits BaseForm

#Region "Fields"
    Private mdtAllInvestors As New DataTable
    Private mdtAllFunds As New DataTable
    Private mdtExistingInvestors As New DataTable
    Private mdtExistingFunds As New DataTable
    Private mblnIsInvestorSucess As Boolean
    Private mblnIsFundSucess As Boolean
    Private mstrScreenName As String = "Existing Investor Fund"
#End Region

#Region "Constructors"

    Sub New(ByVal pdtAllInvestors As DataTable, ByVal pdtAllFunds As DataTable, ByVal pdtExistingInvestors As DataTable, ByVal pdtExistingFunds As DataTable, ByVal pblnIsInvestorSucess As Boolean, ByVal pblnIsFundSucess As Boolean)
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        mdtAllInvestors = pdtAllInvestors
        mdtAllFunds = pdtAllFunds
        mdtExistingInvestors = pdtExistingInvestors
        mdtExistingFunds = pdtExistingFunds
        mblnIsInvestorSucess = pblnIsInvestorSucess
        mblnIsFundSucess = pblnIsFundSucess
    End Sub
#End Region

#Region "Load"

    Private Sub ExistingInvestorFund_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetOnLoadControls()
        Dim lstrQuery As String
        Dim larrExistingRows() As DataRow
        Try
            'Check if the investor was a success so that window's size can be adjusted
            If mblnIsInvestorSucess Then
                grdExistingInvestor.Visible = False
                grdExistingInvestor.Size = New Drawing.Size(0, 0)
            Else
                'Check if the fund was a success so that window's size can be adjusted
                If mblnIsFundSucess Then
                    grdExistingInvestor.Size = New Drawing.Size(grdExistingInvestor.Width, Me.Height - btnExit.Height - 40)
                Else
                    grdExistingInvestor.Size = New Drawing.Size(grdExistingInvestor.Width, Me.Height / 2 - 40)
                End If
                grdExistingInvestor.DataSource = mdtAllInvestors
                For Each lrow As UltraGridRow In grdExistingInvestor.Rows
                    lrow.Hidden = True
                Next
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("InvestorID").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("RowNumber").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("InvEntityID").Hidden = True
                grdExistingInvestor.Rows.Band.Columns("Mapped Inv. Name").Width = 250
                grdExistingInvestor.Rows.Band.Columns("Mapped Fund Name").Width = 250

                grdExistingInvestor.DisplayLayout.Bands(0).Columns("Investor Type").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("Master Investor Type").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("Head Investor").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("Style").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("Turnover").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("City").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("State").Hidden = True
                grdExistingInvestor.DisplayLayout.Bands(0).Columns("Country Name").Hidden = True

                'To show the investors which already exists in the database
                For Each lRow As DataRow In mdtExistingInvestors.Rows
                    lstrQuery = "[Mapped Inv. Name]" + " ='" + lRow.Item("Investor Name").ToString + "'"
                    larrExistingRows = mdtAllInvestors.Select(lstrQuery)
                    If larrExistingRows.Length > 0 Then
                        For Each lExistingRow As DataRow In larrExistingRows
                            grdExistingInvestor.Rows(mdtAllInvestors.Rows.IndexOf(lExistingRow)).Hidden = False
                            Exit For
                        Next
                    End If
                Next
                grdExistingInvestor.UpdateData()
                grdExistingInvestor.Visible = True
            End If
            If mblnIsFundSucess Then
                grdExistingFund.Visible = False
                grdExistingFund.Size = New Drawing.Size(0, 0)
            Else
                'Check if the investor was a success so that window's size can be adjusted
                If mblnIsInvestorSucess Then
                    grdExistingFund.Location = grdExistingInvestor.Location
                    grdExistingFund.Size = New Drawing.Size(grdExistingFund.Width, Me.Height - btnExit.Height - 40)
                Else
                    'Check if the fund was a success so that window's size can be adjusted
                    grdExistingFund.Location = New Point(grdExistingFund.Location.X, grdExistingInvestor.Height + 10)
                    grdExistingFund.Size = New Drawing.Size(grdExistingFund.Width, Me.Height / 2 - 40)
                End If
                grdExistingFund.DataSource = mdtAllFunds
                For Each lrow As UltraGridRow In grdExistingFund.Rows
                    lrow.Hidden = True
                Next
                grdExistingFund.DisplayLayout.Bands(0).Columns("FundID").Hidden = True
                grdExistingFund.DisplayLayout.Bands(0).Columns("RowNumber").Hidden = True
                grdExistingFund.DisplayLayout.Bands(0).Columns("FundEntityID").Hidden = True
                grdExistingFund.Rows.Band.Columns("Mapped Inv. Name").Width = 250
                grdExistingFund.Rows.Band.Columns("Mapped Fund Name").Width = 250

                grdExistingFund.DisplayLayout.Bands(0).Columns("Fund Type").Hidden = True
                grdExistingFund.DisplayLayout.Bands(0).Columns("Style").Hidden = True
                grdExistingFund.DisplayLayout.Bands(0).Columns("Turnover").Hidden = True
                grdExistingFund.DisplayLayout.Bands(0).Columns("Country Name").Hidden = True

                'To show the funds which already exists in the database
                For Each lRow As DataRow In mdtExistingFunds.Rows
                    lstrQuery = "[Mapped Fund Name]" + " ='" + lRow.Item("Fund Name").ToString + "'"
                    larrExistingRows = mdtAllFunds.Select(lstrQuery)
                    If larrExistingRows.Length > 0 Then
                        For Each lExistingRow As DataRow In larrExistingRows
                            grdExistingFund.Rows(mdtAllFunds.Rows.IndexOf(lExistingRow)).Hidden = False
                            Exit For
                        Next
                    End If
                Next
                grdExistingFund.UpdateData()
                grdExistingFund.Visible = True
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, 0)
        Finally
            larrExistingRows = Nothing
        End Try
    End Sub

    Public Sub SetOnLoadControls()
        Me.Text = TitleManager.GetTitle("ExistingInvestorFund")
        Me.WindowState = FormWindowState.Maximized
    End Sub
#End Region

#Region "Events"

#Region "Button Events"
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
#End Region

#End Region

End Class